<template>
  <div class="isbody">
    <el-card shadow="never">
      <el-row>
        <el-col :span="6">
          <div class="txts">仓库编号</div>
          <el-input v-model="addFrom.like_code" placeholder="请输入" />
        </el-col>
        <el-col :span="6">
          <div class="txts">仓库编号</div>
          <el-input v-model="addFrom.like_name" placeholder="请输入" />
        </el-col>
        <el-col :span="6">
          <div class="txts">仓库编号</div>
          <el-select v-model="addFrom.status" placeholder="请选择">
            <el-option label="全部" value="" />
            <el-option label="停用" value="0" />
            <el-option label="启用" value="1" />
          </el-select>
        </el-col>
        <el-col :span="6">
          <div class="isButton">
            <el-button type="primary" round @click="searchList">搜索</el-button>
            <el-button round @click="removeList">重置</el-button>
          </div>
        </el-col>

      </el-row>
    </el-card>
    <el-card shadow="never">
      <el-button type="success" round class="isBurronColor" @click="addList">新增仓库</el-button>
      <el-table
        :data="queryList"
        border
        style="width: 100%"
        stripe
      >
        <el-table-column label="序号" type="index" width="100" />
        <el-table-column
          prop="code"
          label="仓库编码"
          width="120"
        />
        <el-table-column
          prop="name"
          label="仓库名称"
          width="120"
        />
        <el-table-column
          prop="leixing"
          label="仓库类型"
          width="120"
        />
        <el-table-column
          prop="location"
          label="省/市/区"
          width="180"
        />
        <el-table-column
          prop="address"
          label="详细地址"
          width="160"
        />
        <el-table-column
          prop="zhuangtai"
          label="仓库状态"
          width="120"
        />
        <el-table-column
          prop="surface"
          label="仓库面积"
          width="120"
        />
        <el-table-column
          prop="includedNum"
          label="仓库数量"
          width="120"
        />
        <el-table-column
          prop="personName"
          label="负责人"
          width="120"
        />
        <el-table-column
          prop="phone"
          label="联系电话"
          width="150"
        />
        <el-table-column
          prop="createTime"
          label="更新时间"
          width="170"
        />
        <el-table-column
          fixed="right"
          label="操作"
          width="200"
        >
          <template #default="{row}">
            <el-link type="primary" @click="editList(row)">编辑</el-link>
            <el-link type="primary" @click="deactivateList(row)">{{ row.zhuangtai === '启用' ? '停用' : '启用' }}</el-link>
            <el-link class="isLink" type="primary">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="addFrom.current"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="addFrom.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <router-view name="detaill" />
    <!-- 停用 -->
    <el-dialog
      :title="isTitle"
      :visible.sync="deactivateVisible"
      width="30%"
    >
      <div>确定要{{ rows.zhuangtai === '停用' ? '启用': '停用' }} 吗 ？</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deactivateVisible = false">取 消</el-button>
        <el-button type="primary" @click="identifyChanges">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { aaa, editHouseAPI } from '@/api/manage-base-info.js'
export default {
  data() {
    return {
      isBool: null,
      row: {
      },
      deactivateVisible: false,
      //
      addFrom: {
        like_code: '',
        like_name: '',
        status: undefined,
        size: 10,
        descs: 'createTime',
        current: 1
      },
      total: null,
      queryList: [],
      rows: {}
    }
  },
  computed: {
    isTitle() {
      return this.rows.zhuangtai === '停用' ? '启用' : '停用'
    }
  },
  created() {
    this.getAaaList()
  },
  methods: {
    async getAaaList() {
      const res = await aaa(this.addFrom)
      this.queryList = res.data.records
      this.total = res.data.total - 0
      console.log(this.total)
      this.queryList.forEach(item => {
        if (item.type === 'ZZ') {
          item.leixing = '中转仓'
        } else if (item.type === 'JG') {
          item.leixing = '加工仓'
        } else if (item.type === 'CB') {
          item.leixing = '储备仓'
        } else {
          item.leixing = '冷藏仓'
        }
        if (item.status === 0) {
          item.zhuangtai = '停用'
        } else {
          item.zhuangtai = '启用'
        }
      })
      console.log(res)
    },
    // 搜索
    searchList() {
      console.log(this.addFrom)
      this.getAaaList()
    },
    // 重置
    removeList() {
      this.addFrom.like_code = ''
      this.addFrom.like_name = ''
      this.addFrom.status = undefined
      this.getAaaList()
    },
    // 分页逻辑
    handleSizeChange(newSize) {
      this.addFrom.size = newSize
      this.getAaaList()
    },
    handleCurrentChange(newNum) {
      this.addFrom.current = newNum
      this.getAaaList()
    },
    // 新增仓库
    addList() {
      const id = NaN
      this.$router.push(
        { name: `detaill`, params: { id: `${id || 'null'}` }}
      )
    },
    editList(row) {
      // console.log(row.id)
      this.row = row
      this.$router.push(
        { name: `detaill`, params: { id: `${row.id || 'null'}` }}
      )
    },
    deactivateList(row) {
      this.rows = row
      console.log(row)
      this.deactivateVisible = true
    },
    async identifyChanges() {
      if (this.rows.status === 1) {
        this.isBool = 0
      } else {
        this.isBool = 1
      }
      await editHouseAPI({ id: this.rows.id, status: this.isBool })
      this.deactivateVisible = false
      this.getAaaList()
    }
  }
}
</script>
<!-- status -->
<style lang="scss">
.isbody{
  padding: 20px 30px;
}
.el-input{

  font-size: 12px;
   ::v-deep .el-input__inner{
      height: 40px;
    line-height: 40px;
    border: 1px solid #f8f5f5;
    background: #f8f5f5;
    border-radius: 6px;
    }
}
.el-col {
  padding: 10px 3px 10px 3px;
  padding-left: 15px;
    padding-right: 15px;
}
.txts{
  margin-bottom: 10px;
    height: 18px;
    font-size: 12px;
    color: #887e7e;
    font-weight: 500;
    font-family: PingFangSC,PingFangSC-Medium;
}
::v-deep .el-input__inner{
  height: 40px;
    line-height: 40px;
    border: 1px solid #f8f5f5;
    background: #f8f5f5;
    border-radius: 6px;
    width: 100%;
}
.el-select{
  width: 100%;
}
.el-button{
  color: #000;
  margin-right: 5px;
}
.isButton{
  margin-top: 30px;
  float: right;
}
.el-card{
  margin-bottom: 20px;
}
.isBurronColor{
  color:#fff;
  margin-bottom: 20px;
}
.cell{
  color: #000;
}

</style>
